﻿using Newtonsoft.Json;
using QRHelper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using wareHouse;

namespace ShuoXiangProductionPlatform
{
    public partial class BaoZhuangGuanLian : Form
    {
        public BaoZhuangGuanLian()
        {
            this.FormBorderStyle = FormBorderStyle.None;
            InitializeComponent();
            this.label10.Hide();
            this.label11.Hide();
            this.label12.Hide();
           
          
        }

        public bool isstart = false;
        public bool isscan = false;
        public string taginfo = null;
     

        public void StartScan(string qrcode)
        {
           
            if (isscan == true)
            {
                isscan = false;
                this.label11.Text = "扫描成功";
                this.label11.Show();
                this.timer2.Enabled = true;
                this.timer2.Interval = 2000;
                this.timer2.Tick += Timer2_Tick;
                this.label7.Text = qrcode;
                PackInfo packInfo = new PackInfo() { qrcode = qrcode, uid = taginfo, userId = Login.login.userInfo.logindata.userId };
                string param = JsonConvert.SerializeObject(packInfo);
                HttpHelper httpHelper = new HttpHelper();
                string res = httpHelper.HTTPJsonPost("http://47.102.195.242:28083/qrcode/submit/p", param);
                var resjson = JsonConvert.DeserializeObject<JsonString.ApiMsgList<JsonString.orderlistdata>>(res);
                if (resjson.success.Equals("T"))
                {
                    this.label12.Text = "绑定成功";
                    this.timer3.Enabled = true;
                    this.timer3.Interval = 2000;
                    this.timer3.Tick += Timer3_Tick;
                }
                else
                {
                    this.label12.Show();
                    this.label12.Text = "绑定失败" + resjson.msg;
                    this.timer3.Enabled = true;
                    this.timer3.Interval = 2000;
                    this.timer3.Tick += Timer3_Tick;
                }
                this.label4.Text = "";
                this.label7.Text = "";
                 
            }
        }

        private void Timer3_Tick(object sender, EventArgs e)
        {
            this.label12.Hide();
            this.timer3.Enabled = false;
        }

        private void Timer2_Tick(object sender, EventArgs e)
        {
            this.timer2.Enabled = false;
            this.label11.Hide();
        }

        public void StartCoding(string tagInfo)
        {
            if (isstart == true)
            {
                string[] arrs = tagInfo.Split(',');
                if (arrs.Length > 1 && arrs[0].Split(':').Length < 2)
                {
                    string uid = arrs[1];
                    this.label10.Text = "扫描成功";
                    this.label10.Show();
                    this.timer1.Enabled = true;
                    this.timer1.Interval = 2000;
                    this.timer1.Tick += Timer1_Tick;
                    isscan = true;
                    this.taginfo = uid;
                    this.label4.Text = uid;
                }
                else
                {
                    this.label10.Text = "扫描失败";
                    this.label10.Show();
                    this.timer1.Enabled = true;
                    this.timer1.Interval = 2000;
                    this.timer1.Tick += Timer1_Tick;
                }
            }
        }

        private void Timer1_Tick(object sender, EventArgs e)
        {
            this.timer1.Enabled = false;
            this.label10.Hide();
        }
    }
}
